package settingsapp.settings.toggle;

import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import ece.settingsapp.R;

public class SettingWifi extends ToggleSettingChanger
{
	private WifiManager wifiManager;
	
	public SettingWifi(Context context, int intRepresentation)
	{
		super(context, intRepresentation);
		this.context = context;
		wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	}
	
	protected void setValue(boolean isOn)
	{
		this.isOn = isOn;
		wifiManager.setWifiEnabled(this.isOn);
		Intent intent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION);
		context.sendBroadcast(intent);
	}

	@Override
	public void readValue()
	{
		// TODO need to handle special cases of transitory
		// states (where wifi is being disabled or enabled)
		
//		int wifiState = wifiManager.getWifiState();
//		// set state as "off" if wifi is being disabled 
//		value = !(wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING);
		isOn = wifiManager.isWifiEnabled();
	}

	@Override
	public int getResourceOn()
	{
		return R.drawable.wifi_on;
	}

	@Override
	public int getResourceOff()
	{
		return R.drawable.wifi_off;
	}
}
